var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("CarConstant"),
s = t("GlobalUserData"),
l = t("BoxGetItem"),
c = t("HallConstant"),
d = t("HallScene"),
h = t("BroadCastMessage"),
p = t("Util"),
u = t("Particle"),
f = t("ChampionManager"),
m = t("CarConstant"),
_ = t("BuffTip"),
y = t("ConfirmRewardPanel"),
g = cc._decorator,
v = g.ccclass,
C = g.property,
b = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.label_value = null,
        e.arr_frame_nameplate = [],
        e.spr_nameplate = null,
        e.arr_frame_title = [],
        e.spr_title = null,
        e.node_giftcon = null,
        e.pfb_item = null,
        e.pfb_particle = null,
        e.frame_gold = null,
        e.frame_diamond = null,
        e.node_btnGet = null,
        e.label_status = null,
        e.node_masking = null,
        e.pfb_tip = null,
        e._data = null,
        e.scriptItem = null,
        e
    }
    return n(e, t),
    e.prototype.refreshData = function(t, e) {
        this._data = t,
        e ? (this.spr_nameplate.spriteFrame = this.arr_frame_nameplate[f.default.Ins.getGradeLevel(t.trophy)], this.spr_title.spriteFrame = this.arr_frame_title[f.default.Ins.getGradeLevel(t.trophy)]) : this.spr_nameplate.node.active = !1,
        this.label_value.string = t.trophy.toString(),
        this.refreshGiftView(this._data),
        this.refreshStatus()
    },
    e.prototype.refreshGiftView = function(t) {
        if (!this.scriptItem) {
            var e = cc.instantiate(this.pfb_item);
            e.scale = .5,
            this.scriptItem = e.getComponent(l.default),
            this.node_giftcon.addChild(e)
        }
        this.scriptItem.updateView(t)
    },
    e.prototype.refreshStatus = function() {
        this.node_masking.active = !1,
        s.default.gradeRewardList[this._data.index].isGot ? (this.label_status.string = "已领取", this.node_btnGet.active = !1, this.node_masking.active = !0) : s.default.nTrophy < this._data.trophy ? (this.label_status.string = "未达成", this.node_btnGet.active = !1) : (this.label_status.string = "未领取", this.node_btnGet.active = !0)
    },
    e.prototype.getGift = function() {
        var t, e, o = this;
        switch (h.default.getInstance().SendMessage(c.Broadcast_Func.Audio, c.Audio_ID.btn_click), this._data.type) {
            case r.Basics_Items_Type.gold:
                p.Util.showConfirmPanel([{
                type:
                    y.rewardType.gold,
                num: this._data.num
            }],
            function() {
                s.default.saveGoldData(!0, o._data.num),
                cc.find("Canvas").getComponent(d.default).onSetOwnGold(!0),
                o.action(o.frame_gold, "frame_gold")
            },
            !1);
            break;
            case r.Basics_Items_Type.diamond:
                p.Util.showConfirmPanel([{
                type:
                    y.rewardType.diamond,
                num: this._data.num
            }],
            function() {
                s.default.saveDiamondData(!0, o._data.num),
                cc.find("Canvas").getComponent(d.default).onSetOwnDiamond(!0),
                o.action(o.frame_diamond, "frame_diamond")
            },
            !1);
            break;
            default: t = p.Util.getCarBaseData(this._data.id),
            p.Util.showConfirmPanel([{
                type: y.rewardType.item,
                num: this._data.num,
                itemData: t
            }],
            function() {
                t.buff = m.getBuffItem(t),
                e = {
                    data: t,
                    star: o._data.star
                },
                s.default.saveOwnCarData([p.Util.getCarItemData(null, e.data, e.star)])
            },
            !1);
        }
        s.default.gradeRewardList[this._data.index].isGot = !0,
        s.default.saveGradeRewardList(),
        this.refreshStatus()
    },
    e.prototype.action = function(t, e) {
        h.default.getInstance().SendMessage(c.Broadcast_Func.Audio, c.Audio_ID.get_gold);
        for (var o = 0; o < 20; o++) {
            var i = cc.instantiate(this.pfb_particle),
            n = this.node_giftcon.convertToWorldSpaceAR(cc.Vec2.ZERO),
            a = cc.find("Canvas").getChildByName(e).getPosition(),
            r = cc.find("Canvas").convertToNodeSpaceAR(n);
            i.setPosition(r),
            i.parent = cc.find("Canvas"),
            i.getComponent(u.default).init(p.Util.getRandomInt(0, 360), p.Util.getRandomInt(200, 400), a, t)
        }
    },
    e.prototype.showBuffTip = function() {
        var t = cc.instantiate(this.pfb_tip);
        this.node.parent.addChild(t),
        t.getComponent(_.default).init(f.default.Ins.getGradeBuff(this._data.trophy, null));
        var e = this.node.convertToWorldSpaceAR(cc.v2(200, 168.893)),
        o = this.node.parent.convertToNodeSpaceAR(e);
        t.setPosition(o)
    },
    a([C(cc.Label)], e.prototype, "label_value", void 0),
    a([C([cc.SpriteFrame])], e.prototype, "arr_frame_nameplate", void 0),
    a([C(cc.Sprite)], e.prototype, "spr_nameplate", void 0),
    a([C([cc.SpriteFrame])], e.prototype, "arr_frame_title", void 0),
    a([C(cc.Sprite)], e.prototype, "spr_title", void 0),
    a([C(cc.Node)], e.prototype, "node_giftcon", void 0),
    a([C(cc.Prefab)], e.prototype, "pfb_item", void 0),
    a([C(cc.Prefab)], e.prototype, "pfb_particle", void 0),
    a([C(cc.SpriteFrame)], e.prototype, "frame_gold", void 0),
    a([C(cc.SpriteFrame)], e.prototype, "frame_diamond", void 0),
    a([C(cc.Node)], e.prototype, "node_btnGet", void 0),
    a([C(cc.Label)], e.prototype, "label_status", void 0),
    a([C(cc.Node)], e.prototype, "node_masking", void 0),
    a([C(cc.Prefab)], e.prototype, "pfb_tip", void 0),
    a([v], e)
} (cc.Component);
o.default = b